package com.googlecode.jsimplemarket.service;

import com.googlecode.jsimplemarket.repository.ObservatieSpatiuComercialRepository; 

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "observatieSpatiuComercialService")
public class ObservatieSpatiuComercialService {
	@Autowired
	private ObservatieSpatiuComercialRepository observatieSpatiuComercialRepository;
	
	
	private Date getDataInceputZi(Date data) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTime(data);
        gregorianCalendar.set(GregorianCalendar.HOUR, 0);
        gregorianCalendar.set(GregorianCalendar.MINUTE, 0);
        gregorianCalendar.set(GregorianCalendar.SECOND, 0);
        gregorianCalendar.set(GregorianCalendar.AM_PM, GregorianCalendar.AM);
        return gregorianCalendar.getTime();
    }
    
    private Date getDataSfarsitZi(Date data) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTime(data);
        gregorianCalendar.set(GregorianCalendar.AM_PM, GregorianCalendar.PM);
        gregorianCalendar.set(GregorianCalendar.HOUR, 11);
        gregorianCalendar.set(GregorianCalendar.MINUTE, 59);
        gregorianCalendar.set(GregorianCalendar.SECOND, 59);
        return gregorianCalendar.getTime();
    }
    
    private GregorianCalendar getTodayCalendar() {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.set(GregorianCalendar.HOUR_OF_DAY, 0);
        calendar.set(GregorianCalendar.MINUTE, 0);
        calendar.set(GregorianCalendar.SECOND, 0);
        //calendar.set(GregorianCalendar.AM_PM, GregorianCalendar.AM);
        calendar.set(GregorianCalendar.MILLISECOND, 0);
        return calendar;
    }
    
    private Date getTodayDate() {
        return getTodayCalendar().getTime();
    }
    
    private Date addDays(Date date, int days) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(Calendar.DATE, days);
                 
        return cal.getTime();
    }
    
    private Date get7DayDate() {
        GregorianCalendar calendar = getTodayCalendar();
        calendar.add(GregorianCalendar.DATE, -20);
        
        return calendar.getTime();
    }
    
    private Date getLastMonthDate() {
        GregorianCalendar calendar = getTodayCalendar();
        calendar.set(GregorianCalendar.DATE, 1);
        
        return calendar.getTime();
    }
	
	
    
    public List<Object[]> queryObservatiiByDay(Date data) {
        Date dataStart = addDays(data, -7); //ultimile 7 zile
        return observatieSpatiuComercialRepository.queryObservatiiByDay(dataStart);
    }
    
   

}
